// import { applyMiddleware, legacy_createStore as createstore } from "redux";
// import { composeWithDevTools } from "redux-devtools-extension";
// import thunk from "redux-thunk";

import { combineReducers, configureStore } from "@reduxjs/toolkit";
//引入汇总之后的reducer
// import reducer from "./reducers";
import { persistStore, persistReducer } from "redux-persist";
import { ShopCartSlice  } from "../redux/ShopCart/slice";
import { userSlice } from "./User/slice";
import { productDetailSlice } from "./ProductDetail/slice";
import { productSearchSlice } from "./ProductSearch/slice";
import languageReducer from "./language/languageReducer";
import RecProductReducer from "./recommendProduct/productReducer";
import storage from "redux-persist/lib/storage";
import { orderSlice } from "./order/slice";
const persistConfig = {
  key: "root",
  storage,
  whilelist: ["user"],
};
const rootReducer = combineReducers({
  Language: languageReducer,
  Recommend: RecProductReducer,
  productDetail: productDetailSlice.reducer,
  user: userSlice.reducer,
  productSearch: productSearchSlice.reducer,
  ShopCart:ShopCartSlice.reducer,
  order:orderSlice.reducer
});
const persistedReducer = persistReducer(persistConfig, rootReducer);
// const store = createstore(
//   rootReducer,
//   composeWithDevTools(applyMiddleware(thunk))
// );
const store = configureStore({
  reducer: persistedReducer,
  middleware: (getDefaultMiddleware) => [...getDefaultMiddleware()],
  devTools: true,
});
const persistor = persistStore(store);
export type RootState = ReturnType<typeof store.getState>;

export default { store, persistor };
